Skip to content

Centralize enable option handling in the factory#324

Open
watson wants to merge 2 commits into
masterfrom
watson/DEBUG-5291/fix-enable
Open

Centralize enable option handling in the factory#324
watson wants to merge 2 commits into
masterfrom
watson/DEBUG-5291/fix-enable

Conversation

@watson
Copy link
Copy Markdown
Contributor

@watson watson commented Apr 19, 2026

What and why?

The six user-facing plugins (apps, error-tracking, live-debugger, metrics, output, rum) each had a divergent implementation for resolving their enable config boolean:

  • Two code patterns: apps and live-debugger used explicit ?? nullish coalescing, while the other four used a spread-override trick (enable: !!config[KEY], ...config[KEY]) that relies on property ordering.
  • Inconsistent validation: Only live-debugger rejected non-boolean values; the rest silently coerced.
  • Incomplete docs: output and metrics documented default: true (misleading — it's false when the config block is absent), and error-tracking had no enable section at all.

This PR makes the factory the single owner of enable resolution so every plugin shares one set of semantics — and individual plugins stop having to think about enable at all.

How?

Factory becomes the gate (@dd/factory):
Each user-facing plugin's <configKey>.enable is resolved once in the factory's plugin loop, before the plugin's getPlugins is even called. If it resolves to false, the plugin is never instantiated, never validated, never hooked in. As far as the rest of the build is concerned, it doesn't exist.

Shared helper (@dd/core/helpers/options):

  • resolveEnable(options, configKey, log) — single source of truth used by the factory. Emits a deprecation warning (once per key) when a non-boolean value is passed, coercing it with !! to avoid breaking existing users. A TODO(next major) marks the coercion site for removal.

Plugins simplified:

  • getPlugins no longer has an if (!validatedOptions.enable) return [] guard.
  • validateOptions no longer calls resolveEnable; apps, output, and metrics no longer need a log parameter at all.
  • Each <Plugin>OptionsWithDefaults type drops enable — the factory guarantees it's true when plugin code runs, so it's meaningless in the resolved shape.
  • live-debugger now uses the same soft coercion as everyone else (with a deprecation warning) instead of throwing on non-boolean values. Strict rejection moves to the next major along with the others.

Integrity tooling:
The #configs-injection-marker block now emits [name, CONFIG_KEY, getPlugins] triples so the factory's enable loop stays in sync as plugins are added or removed. The create-plugin scaffolding follows the same pattern (no enable guard, no enable in OptionsWithDefaults).

Documentation:

  • Every user-facing plugin's README now has an identical ### <key>.enable section with the correct default wording: true when a <key> config block is present, false otherwise.
  • error-tracking gained its missing enable section and TOC entry.
  • live-debugger's README updated to reflect the soft coercion (was "Must be a boolean").

Tests:

  • Factory gains integration tests covering: missing key → skip, present key → include, enable: false → skip, enable: true → include, non-boolean → coerced + included.
  • Per-plugin enable tests removed from validate.test.ts / index.test.ts (no longer the plugin's contract).
  • live-debugger's strict-rejection tests removed (no longer the contract).

@watson watson mentioned this pull request Apr 19, 2026
Copy link
Copy Markdown
Contributor Author

watson commented Apr 19, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

Base automatically changed from watson/DEBUG-5291/add-live-debugger-plugin to master April 20, 2026 13:42
@watson watson force-pushed the watson/DEBUG-5291/fix-enable branch from 430542d to dd508cf Compare April 20, 2026 14:58
@watson watson force-pushed the watson/DEBUG-5291/fix-enable branch from dd508cf to 00679a8 Compare May 12, 2026 05:31
Copy link
Copy Markdown
Member

@yoannmoinet yoannmoinet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good.

I wonder if we could handle one level higher than just resolveEnable and have something like a global validateOptions, that would, for now, validate enable.

It would be called from each plugin, but would be implemented, tested and documented just once.
Since this is a standard, this can be documented just at the root, once, and not for each individual plugin.

Or alternatively, handle this at the factory level directly, where we also have an validateOptions too.

for (const [name, getPlugins] of pluginsToAdd) {
context.plugins.push(
...wrapGetPlugins(
context,
getPlugins,
name,
)({
bundler,
context,
options,
data,
stores,
}),
);
}

This way, plugins themselves don't even have to handle it.
The standard is applied by design.

I think I prefer the factory approach after all.

WDYT?

Comment thread packages/plugins/apps/src/validate.test.ts Outdated
Comment thread packages/plugins/rum/README.md Outdated
watson added 2 commits May 13, 2026 07:39
Introduce a shared `resolveEnable` helper in @dd/core that all six
user-facing plugins now use to resolve their `enable` config flag.
This replaces the two divergent patterns (explicit `??` vs spread-
override) with a single greppable call site per plugin.

Non-boolean values continue to be coerced for backwards compatibility
but now emit a deprecation warning so strict validation can land in
the next major. live-debugger retains its existing hard rejection via
the companion `validateEnableStrict` helper.

Also fixes the misleading `default: true` wording in the output and
metrics READMEs, adds the missing `errorTracking.enable` docs section,
and authors a full README for the rum plugin (lost in the sourcemaps
extraction refactor of 804f917).
@watson watson force-pushed the watson/DEBUG-5291/fix-enable branch from 00679a8 to f847e1a Compare May 13, 2026 05:46
@watson watson changed the title Standardize enable option handling across all plugins Centralize enable option handling in the factory May 13, 2026
@watson watson marked this pull request as ready for review May 13, 2026 05:54
@watson watson requested review from a team as code owners May 13, 2026 05:54
@watson watson requested review from jakub-g, oliverli and yoannmoinet and removed request for a team May 13, 2026 05:54
Copy link
Copy Markdown
Member

@jakub-g jakub-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I defer review to Yoann here :)

@oliverli
Copy link
Copy Markdown
Collaborator

@cursor review
@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Collaborator

@oliverli oliverli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good for apps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants